#include <ooGame/Game>

#include <osg/Timer>
#include <osg/Math>

#include <osgODE/RigidBody>

#include <OpenThreads/Thread>




#ifndef OOGAME_DATA_PATH
#define OOGAME_DATA_PATH "../../data"
#endif




using namespace ooGame ;




class MySensor: public Sensor
{
public:
    virtual bool    pulse( osgODE::RigidBody* body, Game* game )
    {
        float   value = cos( osg::PI * m_timer.time_s() ) ;
        bool    active = value > 0.0 ;

        printf("sensor:   %.2f\n", value) ;

        return active ;
    }


private:
    osg::Timer  m_timer ;
} ;




class MyActuator: public Actuator
{
public:
    virtual void    actuate( osgODE::RigidBody* body, Game* game )
    {
        printf("actuator: %s\n", isActive() ? "ON" : "OFF") ;
    }
} ;




int
main(int argc, char** argv)
{
    osg::ref_ptr<osgODE::RigidBody> body = new osgODE::RigidBody() ;


    osg::ref_ptr<Game>          game        = new Game() ;
    osg::ref_ptr<Sensor>        sensor      = new MySensor() ;
    osg::ref_ptr<Controller>    controller  = new Controller( Controller::AND ) ;
    osg::ref_ptr<Actuator>      actuator    = new MyActuator() ;



    game->setState( 1 ) ;

    game->getSensorList()       .push_back( sensor ) ;
    game->getControllerList()   .push_back( controller ) ;
    game->getActuatorList()     .push_back( actuator ) ;

    sensor->getControllerList()     .push_back( 0 ) ;
    controller->getActuatorList()   .push_back( 0 ) ;


    for(;;) {
        printf("\n") ;
        (*game)(body) ;
        OpenThreads::Thread::microSleep( 1e5 ) ;
    }


    return 0 ;
}
